package com.example.sisko_app;

import java.util.List;

import com.example.queryObjects.ViewModel;
import com.example.sisko_database.DatabaseQuery;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class FavoriteActivity extends Activity {
	
	private ListView favorite_listeFavoriten;
	private TextView favorite_TextFavorite;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_favorite);
		
		DatabaseQuery query = new DatabaseQuery(this);
		final List<ViewModel> ViewModelList = query.getFavList();
		query.close();
		
		favorite_TextFavorite = (TextView)findViewById(R.id.favorite_TextFavorite);
		favorite_TextFavorite.setText("Favoriten");
		Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/days.otf");
		favorite_TextFavorite.setTypeface(tf);
		
		favorite_listeFavoriten = (ListView)findViewById(R.id.favorite_listeFavoriten);
		favorite_listeFavoriten.setAdapter(new ArrayAdapter<ViewModel>(this,android.R.layout.simple_list_item_1, ViewModelList));
		favorite_listeFavoriten.setOnItemClickListener(new OnItemClickListener() {
			
			public void onItemClick(AdapterView<?> arg0, View arg1, int position,
					long arg3) {
				
				Intent switchLocation = new Intent(arg1.getContext(), RestaurantActivity.class);
				switchLocation.putExtra("LocID", String.valueOf(ViewModelList.get(position).getLocID()));
				startActivity(switchLocation);
				
			}
		});
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_favorite, menu);
		return true;
	}

}
